#!/bin/bash

#gphoto2 --force-overwrite --filename "start.%C" --capture-image-and-download


#output path

#output filename

#hold time
holdtime=0s

#wait time
waittime=2s





#capture count
capturecount=0

function zoom {
	
	#$1 = number of steps
	#$2 = step direction
	
	command="gphoto2 --force-overwrite --capture-preview"
	
	for i in `seq 1 $1`;
	do
		command="$command --set-config manualfocusdrive=$2"
	done
	
	$command
	
}

function zoom_and_capture {
	
	#$1 = number of steps
	#$2 = step direction
	#$3 = hold time
	#$4 = wait time
	
	zoom $1 $2
	
	capturecount=$[capturecount + 1]
	
	gphoto2 --force-overwrite --filename "output_$capturecount.%C" \
	--set-config eosremoterelease=Immediate \
	--wait-event=$3 \
	--set-config eosremoterelease=Off \
	--wait-event-and-download=$4
	
}

function capture_no_af {
	
	#$1 = hold time
	#$2 = wait time
	
	capturecount=$[capturecount + 1]
	
	gphoto2 --force-overwrite --filename "output_$capturecount.%C" \
	--set-config eosremoterelease=Immediate \
	--wait-event=$1 \
	--set-config eosremoterelease=Off \
	--wait-event-and-download=$2
		
}

function capture_tv {
	
	#$1 = tv
	#$2 = hold time
	#$3 = wait time
	
	capturecount=$[capturecount + 1]
	
	#/main/settings/capturetarget
	
	gphoto2 --quiet \
	--force-overwrite \
	--filename "output_$capturecount.%C" \
	--set-config capturetarget=0 \
	--set-config shutterspeed=$1 \
	--set-config eosremoterelease=Immediate \
	--wait-event=$2 \
	--wait-event-and-download=$3
	
}



	
#from current position

#backup 90
zoom 30 0
zoom 30 0
zoom 30 0

#step and capture forward 90
for i in `seq 1 90`;
do
	zoom_and_capture 1 4 $holdtime $waittime
done

#capture 180
for i in `seq 1 180`;
do
	capture_no_af $holdtime $waittime
done

#step and capture back 90
for i in `seq 1 90`;
do
	zoom_and_capture 1 0 $holdtime $waittime
done


exit


